
// 粘贴子表逻辑

import pasteSubTableRow from '../../request-functions/pasteSubTableRow';
import deepCopy from '../../../../public/functions/deep-copy';

import {
    toast
} from 'nc-lightapp-front';

import language from '../../language';

export default async function (tableId, index) {

    const {
        copyData: originData,
        humanResourceOrganizationValue: {
            refpk
        }
    } = this.state;

    let copyData = originData[tableId] || [];
    copyData = deepCopy(copyData);

    if (copyData.length <= 0) {
        toast({
            color: 'warning',
            content: language['hi6007-000062']/* 国际化处理： 没有要粘贴的行*/
        });
    } else {
        let postData = {
            func_type: '4',
            model: {
                areacode: tableId,
                rows: copyData
            },
            pk_org: refpk,
            table_code: tableId
        };

        try {
            let res = await pasteSubTableRow(postData);
            
            res.data[tableId].rows.map((item) => {
                this.props.cardTable.addRow(tableId, index, item.values, false);
            });

            if(res.success) {
                toast({
                    color: 'success',
                    content: language['hi6007-000171']/* 国际化处理： 粘贴成功*/
                });
            }
        }
        catch(e) {
        }

        
    }
}
